{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run the CO-Algorithm on the HIPE data set"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this notebook we use NILMTK's rapid experimentation API to run the CO algorithm on two appliances of the HIPE data set. The goal is to verify that the framework and the transformed data are behaving as expected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from nilmtk.api import API\n",
    "from nilmtk.disaggregate import CO, Mean, FHMMExact, Hart85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "hipe = {\n",
    "  \"power\": {\n",
    "    \"mains\": [\"apparent\"],\n",
    "    \"appliance\": [\"active\"]\n",
    "  },\n",
    "  'sample_rate': 60,\n",
    "  'artificial_aggregate': True,\n",
    "  'appliances': [9,10],\n",
    "  'methods': {\n",
    "      \"CO\":CO({}),\n",
    "      'Mean': Mean({}),\n",
    "      #\"FHMM_EXACT\":FHMMExact({'num_of_states':2})\n",
    "  },\n",
    "  'train': {    \n",
    "    'datasets': {\n",
    "        'HIPE': {\n",
    "            'path': '../test_1week.hdf',\n",
    "            'buildings': {\n",
    "                1: {\n",
    "                    'start_time': '2017-10-23',\n",
    "                    'end_time': '2017-10-24'\n",
    "                    }\n",
    "                }                \n",
    "            }\n",
    "        }\n",
    "    },\n",
    "  'test': {\n",
    "    'datasets': {\n",
    "        'HIPE': {\n",
    "            'path': '../test_1week.hdf',\n",
    "            'buildings': {\n",
    "                1: {\n",
    "                    'start_time': '2017-10-24',\n",
    "                    'end_time': '2017-10-30'\n",
    "                    }\n",
    "                }\n",
    "            }\n",
    "        },\n",
    "        'metrics':['rmse','f1score','mae']\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Joint Testing for all algorithms\n",
      "Loading data for  HIPE  dataset\n",
      "Dropping missing values\n",
      "Creating an Artificial Aggregate\n",
      "Generating predictions for : CO\n",
      "...............CO disaggregate_chunk running.............\n",
      "Generating predictions for : Mean\n",
      "............  rmse  ..............\n",
      "            CO        Mean\n",
      "9    12.995040  351.039083\n",
      "10  246.999486  246.999486\n",
      "............  f1score  ..............\n",
      "          CO      Mean\n",
      "9   0.999717  0.338109\n",
      "10  0.000000  0.000000\n",
      "............  mae  ..............\n",
      "           CO        Mean\n",
      "9    2.963543  256.604553\n",
      "10  79.049049   79.049049\n"
     ]
    }
   ],
   "source": [
    "hipe_results = API(hipe)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HIPE_1_rmse\n",
      "            CO        Mean\n",
      "9    12.995040  351.039083\n",
      "10  246.999486  246.999486\n",
      "\n",
      "\n",
      "\n",
      "HIPE_1_f1score\n",
      "          CO      Mean\n",
      "9   0.999717  0.338109\n",
      "10  0.000000  0.000000\n",
      "\n",
      "\n",
      "\n",
      "HIPE_1_mae\n",
      "           CO        Mean\n",
      "9    2.963543  256.604553\n",
      "10  79.049049   79.049049\n",
      "\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "errors_keys = hipe_results.errors_keys\n",
    "errors = hipe_results.errors\n",
    "for i in range(len(errors)):\n",
    "    print (errors_keys[i])\n",
    "    print (errors[i])\n",
    "    print (\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
